#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONCLIENT_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONCLIENT_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct AccountLogonClientData : public QSharedData
{
  quint8 clientKey[32];
  QByteArray user;
};

class AccountLogonClient : public Message
{
public:
	static const int id = 0x53;
	BNCS_MESSAGE_CLIENT_REGISTER(AccountLogonClient, id);

public:
	QSharedDataPointer<AccountLogonClientData> d;

public:
	AccountLogonClient()
	{
		d = new AccountLogonClientData();
	}
	
	virtual AccountLogonClient* create()
	{
		return new AccountLogonClient();
	}
	
	virtual quint32 id()
	{
		return id;
	}

	virtual int size()
	{
		return sizeof(d->clientKey) + (d->user.size() + 1);
	}

protected:
	virtual void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds.readRawData((char*)d->clientKey, 32);
		d->user = readStringFrom(ds);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	virtual void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds.writeRawData((char*)d->clientKey, 32);
		writeStringTo(ds, d->user);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}

#endif /*NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONCLIENT_H_*/
